package huawei;

/**
 * 推荐多样性
 */
public class Q107 {

    public static void main(String[] args) {
        int N = 4;
        int K = 7;

        int[][] selected = new int[K][N];

        int[][] recallList = {{0, 1, 2, 3, 4, 5, 6, 7 ,8,9}, {10 ,11, 12 ,13 ,14 ,15 ,16 ,17 ,18 ,19},{20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29}};

        int circleSize = recallList.length;

        int[] arr = new int[recallList.length];

        for (int i = 0; i < K; i++) {
            int x = i % circleSize;
            for (int j = 0; j < N; j++) {
                if (arr[x] < recallList[x].length) {
                    selected[i][j] = recallList[x][arr[x]];
                    arr[x] += 1;
                } else {
                    // 这一行不够了，下一行
                    int next = x;
                    while (arr[(++next) % circleSize] >= recallList[next % circleSize].length);
                    selected[i][j] = recallList[next % circleSize][arr[next % circleSize]];
                    arr[next % circleSize] += 1;
                }
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < K; j++) {
                System.out.print(selected[j][i] + " ");
            }
//            System.out.println();
        }
        System.out.println();
        String s = "asdsa;saasdsa;";

        for (String s1 : s.split(";")) {
            System.out.println(s1.length());
        }
    }
}
